{% extends "global/Page.html" %}
{% load otree %}
{% block title %}
Auction
{% endblock %}

{% block content %}
{#这俩应该是常驻的消息 出现新的后就会把旧的顶下去#}
<p id="msg-point-pool"></p>
<p id="msg-my-status"></p>
    <p id="msg-other-status"></p>
{#<p id="msg-my-bid"></p>#}

<button type="button" id="btn-bid" onclick="sendBid(this)"></button>

    <br><br>
{#    这个是提示界面 永续存在#}
    {% include Constants.instructions_template %}
<script>
    {#按钮#}
    let bidBtn = document.getElementById('btn-bid');

    let msgPointPool=document.getElementById('msg-point-pool');



    {#这俩应该是常驻的消息 出现新的后就会把旧的顶下去#}
{#    我的状态#}
    let msgMyStatus = document.getElementById('msg-my-status');
    {#我的投资#}
    let msgMyBid = document.getElementById('msg-my-bid');
    let msgOtherStatus=document.getElementById('msg-other-status')


    function sendBid(btn) {
        liveSend(parseInt(btn.value));
    }

 function liveRecv(data) {
        console.log('liveRecv', data)
        let currentPoint=${data.point_pool}

        msgPointPool.innerText = `现在的总奖池是`+currentPoint+'分，请输入你想分得的分数';


        {# 逻辑 2个人都可以输入自己的数值 输入之后按钮变为disabled 然后服务器将两者结算之后将按钮变为正常#}


        let am_top_bidder = data.top_bidder === js_vars.my_id;
        let am_second_bidder = data.second_bidder === js_vars.my_id;
        let other_is_waiting = data.other_is_waiting===js_vars.my_id;//另一个人是否处于等待 只要有另一个人等待了就行

        {#内容#}
{#     已经提交 等待另一名成员#}
        let is_waiting=data.is_waiting;//初始值为F
        {#尚未提交 #}
        let is_doing=data.isdoing;//初始值为T
        if(is_doing){
            msgMyStatus.innerText = '请输入您的需求：';
            bidBtn.disabled = ''//点击按钮提交框里的金额
            //上面就当是在提交投资

        }
        {#当两人都点击了提交 此时两人的is_waiting都为1#}
        if (!other_is_waiting){//没在等待
            msgOtherStatus.innerText ='另一个人正在输入金额中';
        }else if(other_is_waiting){
            msgOtherStatus.innerText ='另一个人已经提交金额';
        }else {
            msgOtherStatus.innerText ='报错！！！！';
        }

        //提交按钮
        let nextBid = data.top_bid + 10;
        bidBtn.value = nextBid;
        bidBtn.innerText = `Bid ${nextBid} points`;




        if (data.top_bid === 0) {
            msgMyStatus.innerText = 'Nobody has made a bid yet';
        } else if (am_top_bidder) {
            msgMyStatus.innerText = 'You are the top bidder';
            bidBtn.disabled = 'disabled';
            msgMyBid.innerText = `Your bid is ${data.top_bid} points.`;
        } else {
            bidBtn.disabled = '';
            if (am_second_bidder) {
                msgMyBid.innerText = `Your bid is ${data.second_bid} points. The top bid is ${data.top_bid} points (player ${data.top_bidder})`;
                msgMyStatus.innerText = 'You are the second bidder';
            } else {
                msgMyBid.innerText = '';
                msgMyStatus.innerText = 'You are not the top or second bidder.'
            }

        }

    }

    document.addEventListener("DOMContentLoaded", function (event) {
        liveSend({});
    });
</script>


{% endblock %}
